package com.zeta.system.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zeta.system.dao.SysDictMapper;
import com.zeta.system.model.entity.SysDict;
import com.zeta.system.model.poi.SysDictImportVO;
import com.zeta.system.service.ISysDictService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 字典 服务实现类
 *
 * @author AutoGenerator
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class SysDictServiceImpl extends ServiceImpl<SysDictMapper, SysDict> implements ISysDictService {

    /**
     * 批量导入字典
     *
     * @param importDictList 导入的字典列表
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void batchImportDict(List<SysDictImportVO> importDictList) {
        // List<ImportPoi> -> List<Entity>
        List<SysDict> batchList = importDictList.stream()
                .map(it -> BeanUtil.toBean(it, SysDict.class))
                .toList();

        // 批量保存
        this.saveBatch(batchList);
    }
}
